package com.hzdl.flower.service.impl;

import com.hzdl.flower.bean.Cart;
import com.hzdl.flower.mapper.CartMapper;
import com.hzdl.flower.service.CartService;
import com.hzdl.flower.vo.CartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CartServiceImpl implements CartService {
@Autowired
private CartMapper cartMapper;

    @Override
    public int upCart(CartVo cartVo) {

        Cart byUidAndFid = cartMapper.findByUidAndFid(cartVo);
        if (byUidAndFid!=null){
            cartVo.setCount(byUidAndFid.getCount()+cartVo.getCount());
            int i = cartMapper.changeCount(cartVo);
            return i;
        }
        return cartMapper.addCart(cartVo);
    }

    @Override
    public List<Cart> findByUid(CartVo cartVo) {

        return cartMapper.findByUid(cartVo);

    }

    @Override
    public int delCartById(CartVo cartVo) {
        return cartMapper.delCartById(cartVo);
    }
}
